package com.oocl.ita.ui;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import com.oocl.ita.linstner.loginframe.LoginButtonActionListener;

public class LoginFrame extends JFrame {
	JPanel jpanel;	// 放输入框和登录按钮的容器 panel
	JTextField jtpinput;	// 输入account 
	JButton btn;	// 登录按钮
	BackgroundPanel bgp;	// 背景图

	public LoginFrame() {
		init();
	}
	
	private void init() {
		setBounds(new Rectangle(100,100,400,300));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		setResizable(false);
		setTitle("LOGIN");
		
		
		setLayout(null);
		
		JTextField jtfinput=new JTextField();
		jtfinput.setBounds(new Rectangle(101,55,195,37));
		btn = new JButton("login");
		btn.setBounds(new Rectangle(152,128,105,37));
		btn.addActionListener(new LoginButtonActionListener(jtfinput, this));
		
		add(jtfinput);
		add(btn);
		
		// 设置背景
		bgp=new BackgroundPanel((new ImageIcon("login_bg.png")).getImage());  
        bgp.setBounds(0,0,400,300);  
        add(bgp);
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {

			public void run() {
				// TODO Auto-generated method stub
				LoginFrame loginFrame = new LoginFrame();
				loginFrame.setVisible(true);
			}
		});

	}

	// 背景图 
	class BackgroundPanel extends JPanel  
	{  
	    Image im;  
	    public BackgroundPanel(Image im)  
	    {  
	        this.im=im;  
	        this.setOpaque(true);  
	    }  
	    //Draw the back ground.  
	    public void paintComponent(Graphics g)  
	    {  
	        super.paintComponents(g);  
	        g.drawImage(im,0,0,this.getWidth(),this.getHeight(),this);  
	          
	    }  
	}  
}
